package com.appspot.etao.model;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.appspot.etao.util.StringUtil;
import com.taobao.top.domain.ShopCat;

@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class ShopCatModel extends BaseModel {

	private static final long serialVersionUID = -4209725700582577181L;

    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	private Long id;

    /** 卖家自定义类目编号 */
    @Persistent
    private Long cid;

    /** 父类目编号 */
    @Persistent
    private Long parentCid;

    /** 卖家自定义类目名称 */
    @Persistent
    private String name;

    /** 该类目是否为父类目 */
    @Persistent
    private Boolean isParent;
    
    private ShopCat shopCat;
    
    public ShopCatModel() {
    	
    }
    
    public ShopCatModel(ShopCat shopCat) {
    	setShopCat(shopCat);
    }

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public Long getCid() {
		return cid;
	}

	public void setCid(Long cid) {
		this.cid = cid;
	}

	public Long getParentCid() {
		return parentCid;
	}

	public void setParentCid(Long parentCid) {
		this.parentCid = parentCid;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Boolean getIsParent() {
		return isParent;
	}

	public void setIsParent(Boolean isParent) {
		this.isParent = isParent;
	}

	public ShopCat getShopCat() {
		return shopCat;
	}

	public void setShopCat(ShopCat shopCat) {
		this.shopCat = shopCat;
		
		this.cid = shopCat.getCid();
		this.parentCid = shopCat.getParentCid();
		this.name = StringUtil.cut(shopCat.getName());
		this.isParent = shopCat.isParent();
	}
	
	public String toString() {
		StringBuffer sb = new StringBuffer("");
		sb.append("[");
		sb.append(cid);
		sb.append(",");
		sb.append(parentCid);
		sb.append(",");
		sb.append(name);
		sb.append(",");
		sb.append(isParent);
		sb.append("]");

		return sb.toString();
	}
}
